﻿using System;
using System.IO;
using System.Globalization;

using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Configuration.Json;

using System.Text.Json;

namespace Unity.Commons.Examples
{
    class Program
    {
        protected Program() { }

        static void Main(string[] args)
        {
            double testEnvDoubleParamValue = 123.456;
            Console.WriteLine(testEnvDoubleParamValue.ToString(CultureInfo.InvariantCulture));
        }
        static void NotMain(string[] args)
        {
            IConfiguration config = null;
            try {
                var configBuilder = new ConfigurationBuilder();
                configBuilder.AddEnvironmentVariables();
                string JsonConfigurationFileName = "appsettings.json";
                string JsonConfigurationFilePath = Path.Combine(Directory.GetCurrentDirectory(), JsonConfigurationFileName);
                //Console.WriteLine(JsonConfigurationFilePath);
                //if (File.Exists(JsonConfigurationFilePath))
                //{
                //    Console.WriteLine($"Json Configuration if found in {JsonConfigurationFilePath}");
                //    configBuilder.AddJsonFile(JsonConfigurationFilePath);
                //}

                //string XmlConfigurationFileName = "appsettings.xml";
                //string XmlConfigurationFilePath = Path.Combine(Directory.GetCurrentDirectory(), XmlConfigurationFileName);
                //Console.WriteLine(XmlConfigurationFilePath);
                //if (File.Exists(XmlConfigurationFilePath))
                //{
                //    Console.WriteLine($"Xml Configuration if found in {XmlConfigurationFilePath}");
                //    configBuilder.AddXmlFile(XmlConfigurationFilePath);
                //}

                configBuilder.AddCommandLine(args);
                config = configBuilder.Build();
                
            } catch(InvalidDataException exception)
            {
                Console.WriteLine(exception);
                Exception innerException = exception.InnerException;
                
                
                Console.WriteLine(innerException.GetType());
                
            }

            Console.WriteLine("Hello World!");
            if(config != null)
            {
                foreach (var child in config.GetChildren())
                {
                    Console.WriteLine(child.Key + " => " + child.Value);
                }
            } 
            else
            {
                Console.WriteLine("Can't load Env variables");
            }
            
            
        }
    }
}
